import os.path
from wwengine.datasets import build_dataset
from wwengine.models import build_detector
from wwengine.config import Config
from wwengine.runner import EpochBasedRunner
from wwengine.utils import get_time_str, get_root_logger, collect_env


if __name__ == '__main__':
    cfg = Config.fromfile('files/default.json')
    tasks = cfg['TASKS']
    hw_data = build_dataset(cfg['DATASETS'], tasks)

    net = build_detector(cfg['DETECTOR'], train_cfg=cfg['train_cfg'], test_cfg=cfg['test_cfg'])
    work_dir = os.path.join(cfg["WORKDIR"], get_time_str())
    logger = get_root_logger()
    # meta = dict()
    # env_info_dict = collect_env()
    # env_info = '\n'.join([(f'{k}: {v}') for k, v in env_info_dict.items()])
    # dash_line = '-' * 60 + '\n'
    # logger.info('Environment info:\n' + dash_line + env_info + '\n' +
    #             dash_line)
    # meta['env_info'] = env_info
    # meta['config'] = cfg.pretty_text
    # meta['seed'] = args.seed
    # meta['exp_name'] = osp.basename(args.config)

    runner = EpochBasedRunner(
        net,
        optimizer=None,
        work_dir=work_dir,
        logger=logger,
        meta=None)

    print(net)
